package com.txsj.scan.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;

import com.txsj.scan.MainActivity;
import com.txsj.scan.R;
import com.txsj.scan.utils.DeviceUtils;
import com.txsj.scan.utils.PreferenceUtil;

/**
 * Created by wangchuangjun on 2019/2/18
 * Desc: 启动页
 */

public class StartActivity extends AppCompatActivity {
    private ImageView iv_start;
    private TextView version_info;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        iv_start = (ImageView) findViewById(R.id.iv_start);
        version_info = (TextView) findViewById(R.id.version_info);
        iv_start.setImageResource(R.mipmap.start_page);
        version_info.setText(getResources().getString(R.string.version)+DeviceUtils.getVersionName(this));
        startAnim();
    }

    public void startAnim() {
        AlphaAnimation anima = new AlphaAnimation(0.8f, 1.0f);
        anima.setDuration(1500);// 设置动画显示时间
        iv_start.startAnimation(anima);
        anima.setAnimationListener(new AnimationImpl());
    }

    private class AnimationImpl implements Animation.AnimationListener {
        @Override
        public void onAnimationStart(Animation animation) {
            iv_start.setBackgroundResource(R.mipmap.start_page);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
//            PreferenceUtil.getInstance().commitInt(PreferenceUtil.USER_ID, 258703);
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.TOKEN, "4C68487038727569626D746D2B4D61744D6D516D55513D3D");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.BRAND_ID, "498529");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.MOBILE, "15311486076");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.COMID, "1");
//            PreferenceUtil.getInstance().commitBoolean(PreferenceUtil.IS_LOGINED, true);

//            客户的信息
//            PreferenceUtil.getInstance().commitInt(PreferenceUtil.USER_ID, 296691);
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.TOKEN, "7077416236596A6342574C626861555556486E5133673D3D");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.BRAND_ID, "498451");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.MOBILE, "13914766166");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.COMID, "550103");
//            PreferenceUtil.getInstance().commitBoolean(PreferenceUtil.IS_LOGINED, true);

//            客户的信息  杭州30万
            PreferenceUtil.getInstance().commitInt(PreferenceUtil.USER_ID, 299159);
            PreferenceUtil.getInstance().commitString(PreferenceUtil.TOKEN, "4E4249716F34757365732F627241746F3157734C49773D3D");
            PreferenceUtil.getInstance().commitString(PreferenceUtil.BRAND_ID, "499875");
            PreferenceUtil.getInstance().commitString(PreferenceUtil.MOBILE, "17858643159");
            PreferenceUtil.getInstance().commitString(PreferenceUtil.COMID, "551803");
            PreferenceUtil.getInstance().commitBoolean(PreferenceUtil.IS_LOGINED, true);

//            PreferenceUtil.getInstance().commitInt(PreferenceUtil.USER_ID, 255385);
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.TOKEN, "61335147414C4D77626432697442744E584635676E413D3D");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.BRAND_ID, "496240");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.MOBILE, "18311483762");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.COMID, "548327");
//            PreferenceUtil.getInstance().commitBoolean(PreferenceUtil.IS_LOGINED, true);

//            PreferenceUtil.getInstance().commitString(PreferenceUtil.BRAND_ID, "496240");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.BRAND_NAME, "都来创业总部店");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.USER_NAME, "18311483762");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.ROLE, "老板");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.LOGO, "https://img.txooo.com/2018/05/23/7edbd152fe7c77672f6f0e1608323dd0.png");
//            PreferenceUtil.getInstance().commitInt(PreferenceUtil.USER_ID, 255385);
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.TOKEN, "61335147414C4D77626432697442744E584635676E413D3D");
//            PreferenceUtil.getInstance().commitString(PreferenceUtil.COMID, "548327");
//            PreferenceUtil.getInstance().commitBoolean(PreferenceUtil.IS_LOGINED, true);

//            /**
//             * 针对1.4.6版本，需要
//             */
//            if (!PreferenceUtil.getInstance().getBoolean(PreferenceUtil.FIRST_ENTER_11,false)){
//                PreferenceUtil.getInstance().removeAll();
//                GreenDaoUtils.getSingleTon().deleteAll(true);
//                ModuleManager.newInstance().setUHFStatus(false);
//                Intent intent = new Intent(StartActivity.this, LoginActivity.class);
//                startActivity(intent);
//                finish();
//                PreferenceUtil.getInstance().commitBoolean(PreferenceUtil.FIRST_ENTER_11,true);
//            }else {
                if (PreferenceUtil.getInstance().getBoolean(PreferenceUtil.IS_LOGINED, false)) {
                    Intent intent = new Intent(StartActivity.this, SelectGoodsListActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    Intent intent = new Intent(StartActivity.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
//            }
//            GZIPUtils.getCount();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    }


    /**
     * 跳转到主页面
     */
    private void goHome() {
        startActivity(new Intent(StartActivity.this, MainActivity.class));
        finish();// 销毁当前活动界面
    }
}
